import os

avrGccDiviceList = ['atmega8', 'atmega16', 'atmega128']#, 'atmega168']
avrGccExamplesList = ['AvrGccSpi', 'AvrGcc7Segments', 'delagate', 'GPIO_GCC_AVR', 'LcdTest', 'matrix_keyb']

def BuildAvrGccSample(deviceName, exampleName):

	avrEnv = Environment(DEVICE_NAME = deviceName, 
		toolpath = ['#/scons'], 
		tools=['mcucpp'])
	avrEnv.Append(CCFLAGS = '-O3' )
	avrEnv.Append(CCFLAGS = '-finline-limit=35')
	sources = avrEnv.Glob(exampleName + '/*.cpp')
	objects = []
	for sourceFile in sources:
		srcName = os.path.splitext(os.path.basename(sourceFile.srcnode().abspath))[0]
		objName = deviceName + '-' + exampleName + '-' + srcName
		objects += avrEnv.Object(objName, sourceFile)
	elf = avrEnv.Program(deviceName + '-' + exampleName, objects)
	lss = avrEnv.Disassembly(elf)
	hex = avrEnv.Hex(elf)


for dev in avrGccDiviceList:
	for example in avrGccExamplesList:
		BuildAvrGccSample(dev, example)
